
<h2 class="title">Crear nuevo usuario</h2>
<div style="clear: both;">&nbsp;</div>
<div class="entry">
    <form name="newuser" method="POST" action="newUser.php" onsubmit="return userSubmit();">
        <table>
            <tr>
                <td>C&oacute;digo:</td>
                <td><input type="text" id="codigo" name="codigo" /></td>
            </tr>
            <tr>
                <td>Nombre completo:</td>
                <td><input type="text" id="nombre" name="nombre" /></td>
            </tr>
            <tr>
                <td>Email:</td>
                <td><input type="text" id="email" name="email" /></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><input type="password" id="passwd1" name="passwd1" /></td>
            </tr>
            <tr>
                <td>Confirmar password:</td>
                <td><input type="password" id="passwd2" name="passwd2" /></td>
            </tr>
        </table>
        <input type="submit" name="sendNewUser" value="Enviar" />
    </form>
</div>

<script type="text/javascript" src="resources/jquery.js"></script>
<script type="text/javascript" src="resources/jquery.form.js"></script>

<script language="javascript" >
    function userSubmit() {        
        var passwd1 = $('#passwd1').val();
        var passwd2 = $('#passwd2').val();
        if (passwd1 != null && passwd1.length >= 5 && passwd1==passwd2)
            return true;
        alert('Las contraseñas no son iguales o son de menos de 5 caracteres');
        return false;
    }
</script>
<?php

include('modelo.php');

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
if ($_POST['sendNewUser']) {
    $codigo = $_POST['codigo'];
    $nombre = $_POST['nombre'];
    $email= $_POST['email'];
    $password1 = $_POST['passwd1'];
    $password2 = $_POST['passwd2'];
    
    if (strcmp($password1, $password2) != 0) {
        exit (0);
    }
    $password = md5($password1);
    $sql = "insert into Usuarios (cod,Nombre,Password,Email) values ('$codigo','$nombre','$password','$email')";
    executeNonQuery($sql);
    $_SESSION['username'] = $codigo;
    header('Location: index.php');
}
?>
